﻿using DevExpress.Data.Filtering.Helpers;
using HalconDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace HTHMachineVision
{

        [Serializable]
        public class MyData
        {
            //Halcon 中 HObject 类型 序列化保存时不能为new，需要有实际的值，或者为null

            //形状模板
            public HShapeModel hShapeModel = new HShapeModel();

            //记录模板A点信息
            public double m_hShapeMode_row = 0.0;
            public double m_hShapeMode_col = 0.0;
            public double m_hShapeMode_ang = 0.0;

            //存放矩形模板数据
            public Dictionary<string, GraphicalData> m_RectangleData = new Dictionary<string, GraphicalData>();

            //不需要保存,矩形测量临时数据
            [NonSerialized]
            public Dictionary<string, GraphicalData> temp_RectangleData = new Dictionary<string, GraphicalData>();

            //机器人坐标数据
            public RobotPoint RobotPointData = new RobotPoint();
       

            //不需要保存,不进行序列化
            [NonSerialized]
            public HRegion noteSvae = new HRegion();

            private int temp1 = 0;
            private double temp2 = 2.2;
            public string temp3 = "3";
            const int temp4 = 4;

            //标记该方法在序列化期间被调用
            [OnSerializing]
            private void OnSerializing(StreamingContext context)
            {
                //举例：在序列化前，修改任何需要修改的状态

                //!= null 表示new 过; IsInitialized()表示有初始化(赋值)
                if (hShapeModel != null && !hShapeModel.IsInitialized())
                {
                    hShapeModel = null;
                }
            }

            //标记该方法在序列化之后被调用
            [OnSerialized]
            private void OnSerialized(StreamingContext context)
            {
                //举例：在序列化之后，恢复任何需要恢复的状态
            }

            //标记该方法在反序列化期间被调用
            [OnDeserializing]
            private void OnDeserialing(StreamingContext context)
            {
                //举例：在反序列化期间，为字段设置默认值
            }

            //标记该方法在反序列化之后被调用
            [OnDeserialized]
            private void OnDeserialized(StreamingContext context)
            {
                //举例：根据字段值初始化瞬间状态（比如num值）
                if (hShapeModel == null)
                {
                    hShapeModel = new HShapeModel();
                }
                //反序列化（读取上来是Null 就实例化）
                if (m_RectangleData == null)
                {
                    m_RectangleData = new Dictionary<string, GraphicalData>();
                }
                if (RobotPointData == null)
                {
                    RobotPointData = new RobotPoint();
                }

        }

    }
    
}
